/**
 * created by 小卷毛, 2020/9/19
 * Copyright (c) 2020, 416143467@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
package com.sgcc.pda.lib_tools_database.factory;

import com.sgcc.pda.lib_tools_database.bean.other.Attach;
import com.sgcc.pda.lib_tools_database.bean.other.RiskCheckPoint;
import com.sgcc.pda.lib_tools_database.gen.AttachDao;
import com.sgcc.pda.lib_tools_database.gen.DaoSession;
import com.sgcc.pda.lib_tools_database.gen.RiskCheckPointDao;

import org.greenrobot.greendao.Property;

import java.util.List;

/**
 * 描 述：
 * 作 者：小卷毛  2020-09-19 16:21
 * 修改描述：
 * 修 改 人：
 * 修改版本：
 */
public class RiskCheckPointImpl extends Abstractable<RiskCheckPoint, RiskCheckPointDao> {

    @Override
    public RiskCheckPointDao getDao(DaoSession session) {
        return session.getRiskCheckPointDao();
    }

    @Override
    public void insert(RiskCheckPoint bean) {
        mCommonDaoUtils.insert(bean);

        List<Attach> childList = new AttachImpl().findByParam(
                new Property[]{AttachDao.Properties.ParentId},
                new String[]{bean.getRecordId()}
        );
        if (childList != null) {
            new AttachImpl().delete(childList);
        }

        List<Attach> items = bean.getAttach();
        if (items != null) {
            for (Attach item : items) {
                item.setParentId(bean.getRecordId());
            }
            new AttachImpl().insertList(items);
        }
    }

    @Override
    public void insertList(List<RiskCheckPoint> list) {
        mCommonDaoUtils.insert(list);

        for (RiskCheckPoint item : list) {
            List<Attach> childList = new AttachImpl().findByParam(
                    new Property[]{AttachDao.Properties.ParentId},
                    new String[]{item.getRecordId()}
            );
            if (childList != null) {
                new AttachImpl().delete(childList);
            }

            List<Attach> inners = item.getAttach();
            if (inners != null) {
                for (Attach inner : inners) {
                    inner.setParentId(item.getRecordId());
                }

                new AttachImpl().insertList(inners);
            }
        }
    }

}
